package com.usian.search.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.search.dtos.UserSearchDto;
import com.usian.model.search.pojos.ApAssociateWords;
import com.usian.search.mapper.ApAssociateWordsMapper;
import com.usian.search.service.ApAssociateWordsService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ApAssociateWordsServiceImpl extends BaseServiceImpl<ApAssociateWordsMapper, ApAssociateWords> implements ApAssociateWordsService {


    @Override
    public ResponseResult search(UserSearchDto dto) {

        if (dto==null)return errorParam;
        if (StringUtils.isEmpty(dto.getSearchWords()))return errorParam;

        IPage pageParam = new Page(0, dto.getPageSize());
        IPage page = page(pageParam, Wrappers.<ApAssociateWords>lambdaQuery().like(ApAssociateWords::getAssociateWords, dto.getSearchWords()));
        return ResponseResult.okResult(page.getRecords());
    }
}
